﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Brain
{
    public static class StereoscopicUtil
    {
        public static void GetFrames(
            int ResolutionWidth, int ResolutionHeight,
            StereoMode StereoMode, 
            out Vector2 leftSize, out Vector2 leftPosition, 
            out Vector2 rightSize, out Vector2 rightPosition)
        {
            leftSize = Vector2.Zero;
            rightSize = Vector2.Zero;

            leftPosition = Vector2.Zero;
            rightPosition = Vector2.Zero;
            switch (StereoMode)
            {
                case Brain.StereoMode.LeftRight:
                    {
                        int halfWidth = ResolutionWidth / 2;
                        leftSize = new Vector2(halfWidth, ResolutionHeight);
                        leftPosition = new Vector2(0, 0);

                        rightSize = new Vector2(halfWidth, ResolutionHeight);
                        rightPosition = new Vector2(halfWidth, 0);
                    }
                    break;
                case Brain.StereoMode.TopBottom:
                    {
                        int halfHeight = ResolutionHeight / 2;
                        leftSize = new Vector2(ResolutionWidth, halfHeight);
                        leftPosition = new Vector2(0, 0);

                        rightSize = new Vector2(ResolutionWidth, halfHeight);
                        rightPosition = new Vector2(0, halfHeight);
                    }
                    break;
            }
        }

        public static Matrix GetFrameMatrix(StereoMode mode)
        {
            switch (mode)
            {
                case StereoMode.LeftRight:
                    {
                        return Matrix.CreateScale(0.5f, 1, 1);
                    }
                case StereoMode.TopBottom:
                    {
                        return Matrix.CreateScale(1, 0.5f, 1);
                    }
            }
            return Matrix.Identity;
        }
    }
}
